import request from "@/utils/request";
export default {
    users:users,
    projects:projects,
};

let _users
function users(refresh, cb) {
    if (!refresh) {
        if (_users && _users.length > 0) return [..._users]
    }
    
    request.get({
        url: "user.list"
    }).then(res => {
        _users = res.result
        if (typeof cb === 'function') {
            cb(_users && _users.length > 0 ? [..._users] : [])
        }
    },res => {
    
    })
    return _users && _users.length > 0 ? [..._users] : []
}


let _projects
function projects(refresh, cb) {
    if (!refresh) {
        if (_projects) return [..._projects]
    }
    
    request.get({
        url: "project.list"
    }).then(res => {
        _projects = res.result
        if (typeof cb === "function") {
            cb(_projects && _projects.length > 0 ? [..._projects] : [])
        }
    },res => {
    
    })
    return _projects && _projects.length > 0 ? [..._projects] : []
}

